package com.example.eurekaconsumer.service.impl;

import com.example.eurekaconsumer.entity.SysUser;
import com.example.eurekaconsumer.mapper.SysUserMapper;
import com.example.eurekaconsumer.service.SysUserService;
import com.example.eurekaconsumer.util.redis.RedisUtil;
import org.omg.CORBA.Object;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @title: SysUserServiceimpl
 * @projectName spring-cloud-demo
 * @Date: 2021/2/23 15:13
 * @Author: lei.yu-esint
 * @Description:
 */
@Service("SysUserService")
public class SysUserServiceimpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public SysUser findAll(String username) {
        return sysUserMapper.findAll(username);
    }

    @Override
    public SysUser doLogin(String username) {
        SysUser list = sysUserMapper.findAll(username);
        return list;
    }

    /**
     * 获取商品列表
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> getGoods() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list = sysUserMapper.getGoods();
        return list;
    }

    /**
     * 分页获取数据
     *
     * @param request
     * @return
     */
    @Override
    public List<Map<String, Object>> getList(HttpServletRequest request, String keywords) {
//        String keywords= "%"+request.getParameter("keywords")+"%";
        String page = (request.getParameter("page")) == null ? "1" : request.getParameter("page");
        String size = (request.getParameter("size")) == null ? "10" : request.getParameter("size");
        Integer sizes = Integer.parseInt(size);
        Integer pages = (Integer.parseInt(page) - 1) * sizes;
        //根据查询条件，到redis里查找数据
        List<Map<String, Object>> list = sysUserMapper.getList(keywords, pages, sizes);
//        redisUtil.ZSetOps.zAdd("keywordsList",list);
        return list;
    }

    /**
     * 获取商品详情
     *
     * @param uuid
     * @return
     */
    @Override
    public Map<String, Object> proInfo(String uuid) {
        Map<String, Object> proInfo = new HashMap<>();
        proInfo = sysUserMapper.proInfo(uuid);
        System.out.println("===========" + proInfo.toString());
        return proInfo;
    }

    /**
     * 获取用户信息
     *
     * @param username
     * @return
     */
    @Override
    public Map<String, Object> getUserInfo(String username) {
        Map<String, Object> userInfo = new HashMap<>();
        userInfo = sysUserMapper.getUserInfo(username);
        System.out.println("userInfo===========" + userInfo.toString());
        return userInfo;
    }

}
